<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>流水查询</title>
    <style>
        :root {
            --primary-color: #165DFF;
            --secondary-color: #4080FF;
            --accent-color: #FF7D00;
            --text-color: #333333;
            --light-text: #666666;
            --bg-color: #F5F7FA;
            --card-bg: #FFFFFF;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --border-radius: 12px;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Inter', sans-serif;
        }

        body {
            background-color: var(--bg-color);
            background-image: 
                radial-gradient(circle at 25% 25%, rgba(22, 93, 255, 0.03) 0%, transparent 50%),
                radial-gradient(circle at 75% 75%, rgba(22, 93, 255, 0.03) 0%, transparent 50%);
            background-attachment: fixed;
            min-height: 100vh;
            color: var(--text-color);
        }

        .header {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            padding: 20px 40px;
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            z-index: 10;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            font-size: 24px;
            font-weight: 700;
            color: var(--primary-color);
            display: flex;
            align-items: center;
        }

        .logo i {
            margin-right: 10px;
            color: var(--accent-color);
        }

        .button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: var(--border-radius);
            cursor: pointer;
            text-decoration: none;
            transition: all 0.3s ease;
            margin-right: 15px;
            display: inline-flex;
            align-items: center;
        }

        .button:hover {
            background-color: var(--secondary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(22, 93, 255, 0.2);
        }

        .button i {
            margin-right: 5px;
        }

        .logout-button {
            background-color: #FF0000;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: var(--border-radius);
            cursor: pointer;
            text-decoration: none;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
        }

        .logout-button:hover {
            background-color: #CC0000;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(204, 0, 0, 0.2);
        }

        .logout-button i {
            margin-right: 5px;
        }

        .nav-buttons {
            display: flex;
            align-items: center;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 120px 40px 40px;
        }

        .profile-name {
            font-size: 28px;
            font-weight: 700;
            margin-bottom: 30px;
            color: var(--primary-color);
        }

        .card-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 20px;
            margin-bottom: 40px;
        }

        .card {
            background: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: 0 8px 30px rgba(22, 93, 255, 0.15);
            padding: 25px;
            transition: all 0.3s ease;
            border: 1px solid rgba(22, 93, 255, 0.1);
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .card::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 6px;
            background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
        }

        .card:hover {
            transform: translateY(-8px);
            box-shadow: 0 12px 40px rgba(22, 93, 255, 0.2);
        }

        .card.active {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.2);
        }

        .card-info {
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
        }

        .card-logo {
            width: 60px;
            height: 60px;
            background-color: rgba(22, 93, 255, 0.1);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 15px;
        }

        .card-logo i {
            font-size: 24px;
            color: var(--primary-color);
        }

        .card-number {
            font-size: 18px;
            font-weight: 500;
            margin-bottom: 10px;
            color: var(--light-text);
        }

        .card-number.full {
            color: var(--text-color);
        }

        .card-balance {
            font-size: 20px;
            font-weight: 700;
            color: var(--primary-color);
        }

        .card-details {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            border-radius: var(--border-radius);
            box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
            padding: 40px;
            z-index: 20;
            width: 90%;
            max-width: 500px;
        }

        .card-details.active {
            display: block;
        }

        .card-details-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
        }

        .card-details-title {
            font-size: 22px;
            font-weight: 700;
            color: var(--primary-color);
        }

        .close-button {
            font-size: 24px;
            color: var(--light-text);
            cursor: pointer;
            transition: color 0.3s ease;
        }

        .close-button:hover {
            color: var(--primary-color);
        }

        .card-details-content {
            margin-bottom: 25px;
        }

        .card-detail-item {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .detail-label {
            color: var(--light-text);
            width: 100px;
            font-size: 14px;
        }

        .detail-value {
            font-size: 16px;
            font-weight: 500;
        }

        .detail-value.hidden {
            color: #999;
        }

        .password-container {
            margin-top: 20px;
        }

        .password-input {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid #E0E3E9;
            border-radius: var(--border-radius);
            font-size: 16px;
            transition: all 0.3s ease;
            margin-bottom: 15px;
        }

        .password-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.2);
        }

        .password-input.shake {
            animation: shake 0.5s;
        }

        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
            20%, 40%, 60%, 80% { transform: translateX(5px); }
        }

        .verify-button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: var(--border-radius);
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .verify-button:hover {
            background-color: var(--secondary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(22, 93, 255, 0.2);
        }

        .verify-button i {
            margin-right: 5px;
        }

        .action-button {
            display: inline-block;
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: var(--border-radius);
            cursor: pointer;
            text-decoration: none;
            font-size: 16px;
            transition: all 0.3s ease;
            margin-top: 30px;
        }

        .action-button:hover {
            background-color: var(--secondary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(22, 93, 255, 0.2);
        }

        .action-button i {
            margin-right: 5px;
        }

        .flow-container {
            background: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: 0 8px 30px rgba(22, 93, 255, 0.15);
            padding: 30px;
            transition: all 0.3s ease;
            border: 1px solid rgba(22, 93, 255, 0.1);
        }

        .flow-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
        }

        .flow-title {
            font-size: 20px;
            font-weight: 700;
            color: var(--primary-color);
        }

        .current-card {
            font-size: 16px;
            color: var(--light-text);
        }

        .flow-table {
            width: 100%;
            border-collapse: collapse;
        }

        .flow-table th,
        .flow-table td {
            padding: 15px;
            border: 1px solid #E0E3E9;
            text-align: left;
        }

        .flow-table th {
            background-color: var(--bg-color);
            font-weight: 600;
        }

        .flow-table tbody tr:hover {
            background-color: rgba(22, 93, 255, 0.05);
        }

        .no-data {
            text-align: center;
            padding: 50px;
            color: var(--light-text);
        }

        .overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(5px);
            z-index: 15;
        }

        .overlay.active {
            display: block;
        }

        .footer {
            text-align: center;
            padding: 20px;
            color: var(--light-text);
            font-size: 14px;
            margin-top: 60px;
        }
        
        /* 筛选器样式 */
        .flow-filter {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 15px;
        }

        .flow-filter select {
            padding: 8px 12px;
            border-radius: var(--border-radius);
            border: 1px solid #E0E3E9;
            background-color: white;
            color: var(--text-color);
            font-size: 14px;
            cursor: pointer;
            outline: none;
            transition: all 0.3s ease;
        }

        .flow-filter select:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.2);
        }
    </style>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        // 当前选中的卡片索引
        let currentCardIndex = -1;
        
        // 卡片数据
        const cardData = [
            {% for card in user.card_info %}
                {
                    cardID: "{{ card.cardID }}",
                    cardType: "{{ card.cardType }}",
                    balance: "{{ card.balance }}",
                    openDate: "{{ card.openDate }}",
                    pass: "{{ card.pass }}",
                    flow: {{ user.trade_flow_info[card.cardID]|tojson }}
                },
            {% endfor %}
        ];

        // 初始化页面
        document.addEventListener('DOMContentLoaded', function() {
            const cards = document.querySelectorAll('.card');
            const cardDetails = document.getElementById('card-details');
            const overlay = document.getElementById('overlay');
            const closeButton = document.getElementById('close-button');
            const passwordInput = document.getElementById('password-input');
            const verifyButton = document.getElementById('verify-button');
            const cardIdElement = document.getElementById('card-id');
            const currentCardElement = document.getElementById('current-card');
            const flowTableBody = document.getElementById('flow-table-body');
            const noDataElement = document.getElementById('no-data');
            const flowFilter = document.getElementById('flow-type-filter');

            // 为每张卡片添加点击事件
            cards.forEach((card, index) => {
                card.addEventListener('click', function() {
                    // 更新当前选中的卡片索引
                    currentCardIndex = index;
                    
                    // 更新卡片详情
                    updateCardDetails(index);
                    
                    // 显示卡片详情和遮罩层
                    cardDetails.classList.add('active');
                    overlay.classList.add('active');
                    
                    // 添加卡片激活状态
                    cards.forEach((c, i) => {
                        if (i === index) {
                            c.classList.add('active');
                        } else {
                            c.classList.remove('active');
                        }
                    });
                });
            });

            // 关闭按钮事件
            closeButton.addEventListener('click', function() {
                cardDetails.classList.remove('active');
                overlay.classList.remove('active');
                passwordInput.value = '';
                cardIdElement.textContent = '************' + cardData[currentCardIndex].cardID.slice(-4);
                cardIdElement.classList.add('hidden');
                verifyButton.innerHTML = '<i class="fa fa-lock"></i> 验证密码';
                verifyButton.style.backgroundColor = '#165DFF';
                passwordInput.disabled = false;
            });

            // 遮罩层点击事件
            overlay.addEventListener('click', function() {
                cardDetails.classList.remove('active');
                overlay.classList.remove('active');
                passwordInput.value = '';
                cardIdElement.textContent = '************' + cardData[currentCardIndex].cardID.slice(-4);
                cardIdElement.classList.add('hidden');
                verifyButton.innerHTML = '<i class="fa fa-lock"></i> 验证密码';
                verifyButton.style.backgroundColor = '#165DFF';
                passwordInput.disabled = false;
            });

            // 验证密码事件
            verifyButton.addEventListener('click', function() {
                if (currentCardIndex >= 0) {
                    const enteredPassword = passwordInput.value;
                    
                    if (enteredPassword === cardData[currentCardIndex].pass) {
                        // 显示完整卡号
                        cardIdElement.textContent = cardData[currentCardIndex].cardID;
                        cardIdElement.classList.remove('hidden');
                        
                        // 更新流水表格
                        updateFlowTable(currentCardIndex);
                        
                        // 更新当前显示的卡片信息
                        currentCardElement.textContent = `当前卡片: ${cardData[currentCardIndex].cardID}`;
                        
                        // 更改按钮样式
                        verifyButton.innerHTML = '<i class="fa fa-check"></i> 验证成功';
                        verifyButton.style.backgroundColor = '#00B42A';
                        passwordInput.disabled = true;
                        
                        // 关闭卡片详情
                        setTimeout(() => {
                            cardDetails.classList.remove('active');
                            overlay.classList.remove('active');
                        }, 1000);
                    } else {
                        // 错误提示
                        cardIdElement.textContent = '验证失败';
                        cardIdElement.classList.add('hidden');
                        
                        // 震动效果
                        passwordInput.classList.add('shake');
                        setTimeout(() => passwordInput.classList.remove('shake'), 500);
                    }
                }
            });
            
            // 筛选器变化事件
            flowFilter.addEventListener('change', function() {
                if (currentCardIndex >= 0) {
                    updateFlowTable(currentCardIndex);
                }
            });
        });

        // 更新卡片详情
        function updateCardDetails(index) {
            const card = cardData[index];
            document.getElementById('card-id').textContent = '************' + card.cardID.slice(-4);
            document.getElementById('card-type').textContent = card.cardType;
            document.getElementById('card-balance').textContent = card.balance;
            document.getElementById('card-open-date').textContent = card.openDate;
        }

        // 更新流水表格（添加筛选功能）
        function updateFlowTable(index) {
            const card = cardData[index];
            const flowTableBody = document.getElementById('flow-table-body');
            const noDataElement = document.getElementById('no-data');
            const filterValue = document.getElementById('flow-type-filter').value;
            
            // 清空表格
            flowTableBody.innerHTML = '';
            
            // 检查是否有流水数据
            if (card.flow && card.flow.length > 0) {
                // 隐藏无数据提示
                noDataElement.style.display = 'none';
                
                // 添加流水数据（应用筛选）
                let hasData = false;
                card.flow.forEach(flow => {
                    // 应用筛选条件
                    if (filterValue === 'all' || flow.tradeType === filterValue) {
                        const row = document.createElement('tr');
                        row.innerHTML = `
                            <td>${flow.tradeDate}</td>
                            <td>${flow.tradeType}</td>
                            <td>${flow.tradeMoney}</td>
                            <td>${flow.remark}</td>
                        `;
                        flowTableBody.appendChild(row);
                        hasData = true;
                    }
                });
                
                // 如果筛选后没有数据，显示提示
                if (!hasData) {
                    noDataElement.style.display = 'table-row';
                    noDataElement.querySelector('td').textContent = '该筛选条件下无流水数据';
                }
            } else {
                // 显示无数据提示
                noDataElement.style.display = 'table-row';
                noDataElement.querySelector('td').textContent = '暂无流水数据';
            }
        }
    </script>
</head>
<body>
    <!-- 顶部导航 -->
    <div class="header">
        <div class="logo">
            <i class="fa fa-bank"></i>
            安心银行
        </div>
        <div class="nav-buttons">
            <a href="/personal" class="button">
                <i class="fa fa-user-circle"></i> 个人中心
            </a>
            <a href="/" class="logout-button">
                <i class="fa fa-sign-out"></i> 退出登录
            </a>
        </div>
    </div>

    <!-- 主要内容 -->
    <div class="container">
        <div class="profile-name">欢迎 {{ user.name }}</div>
        <h2>账户流水查询</h2>

        <!-- 卡片网格 -->
        <div class="card-grid">
            {% for card in user.card_info %}
                <div class="card">
                    <div class="card-info">
                        <div class="card-logo">
                            <i class="fa fa-credit-card"></i>
                        </div>
                        <div class="card-number">
                            ************{{ card.cardID[-4:] }}
                        </div>
                        <div class="card-balance">
                            ¥{{ card.balance }}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>

        <!-- 流水信息 -->
        <div class="flow-container">
            <div class="flow-header">
                <div class="flow-title">账户流水</div>
                <div class="current-card" id="current-card">
                    当前卡片: 请选择一张卡片
                </div>
            </div>
            
            <!-- 筛选器 -->
            <div class="flow-filter">
                <label>筛选交易类型：</label>
                <select id="flow-type-filter">
                    <option value="all">全部类型</option>
                    <option value="存款">存款</option>
                    <option value="取款">取款</option>
                    <option value="转账">转账</option>
                    <option value="收账">收账</option> <!-- 修改此处：消费改为转账转入 -->
                </select>
            </div>
            
            <table class="flow-table">
                <thead>
                    <tr>
                        <th>交易日期</th>
                        <th>交易类型</th>
                        <th>交易金额</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody id="flow-table-body">
                    <!-- 流水数据将通过 JavaScript 动态填充 -->
                </tbody>
                <tbody>
                    <tr id="no-data" style="display: none;">
                        <td colspan="4" class="no-data">
                            <i class="fa fa-info-circle"></i> 暂无流水数据
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <!-- 卡片详情浮窗 -->
    <div id="card-details" class="card-details">
        <div class="card-details-header">
            <div class="card-details-title">卡片详情</div>
            <div id="close-button" class="close-button">&times;</div>
        </div>
        <div class="card-details-content">
            <div class="card-detail-item">
                <div class="detail-label">卡号：</div>
                <div class="detail-value hidden" id="card-id">************{{ user.card_info[0].cardID[-4:] if user.card_info else '0000' }}</div>
            </div>
            <div class="card-detail-item">
                <div class="detail-label">卡类型：</div>
                <div class="detail-value" id="card-type">{{ user.card_info[0].cardType if user.card_info else '未知' }}</div>
            </div>
            <div class="card-detail-item">
                <div class="detail-label">余额：</div>
                <div class="detail-value" id="card-balance">{{ user.card_info[0].balance if user.card_info else '0.00' }}</div>
            </div>
            <div class="card-detail-item">
                <div class="detail-label">开户日期：</div>
                <div class="detail-value" id="card-open-date">{{ user.card_info[0].openDate if user.card_info else '未知' }}</div>
            </div>
        </div>
        <div class="password-container">
            <input type="password" id="password-input" placeholder="输入密码查看完整信息" class="password-input">
            <button id="verify-button" class="verify-button">
                <i class="fa fa-lock"></i> 验证密码
            </button>
        </div>
    </div>

    <!-- 遮罩层 -->
    <div id="overlay" class="overlay"></div>

    <!-- 页脚 -->
    <div class="footer">
        © 2025 安心银行 
    </div>
</body>
</html>